﻿app.controller('ChurchWorkerOrdinationController', ['$scope', 'GlobalService', 'fileUpload', 'ApplicationService', 'alertboxservice', function ($scope, GlobalService, fileUpload, ApplicationService, alertboxservice) {

    $scope.currentPage = 1;
    $scope.searchkey = "";
    $scope.sortmode = "DESC";
    $scope.sortby = "DEFAULT";
    $scope.showgridloader = true;
    $scope.viewmode = 'TABLE';
    $scope.Document = {};
    $scope.mode = 1;
    
    BindGrid();

    GlobalService.GetChurchWorkers().success(function (data) { $scope.Churchworkers = data; });

    $scope.changeEditMode = function (mode) {
        if(mode==1)
        {
            $scope.mode = 2;
        }
        else {
            var url = "AddChurchWorkerOrdination";
            ApplicationService.Save($scope.list, url).success(function (result) {
                alertboxservice.ShowMsg(result, "Ordination details ");
                BindGrid();
                $scope.mode = 1;
            });
        }

    };

    function BindGrid() {
        $scope.showgridloader = true;
        url = "GetChurchWorkerOrdination?ChurchWorkerId=" + getQueryString('ChurchWorkerId');
        ApplicationService.Getdata(url).success(function (data) {
            $scope.showgridloader = false;
            $scope.list = data;
        });
    }

    $scope.delete = function (data, dataid) {
        swal({
            title: "Are you sure?",
            text: "Your will not be able to recover " + data + " Details!",
            type: "warning",
            showCancelButton: true,
            cancelButtonClass: 'btn-outline btn-black mr-10',
            cancelButtonText: 'Cancel',
            confirmButtonClass: "btn-danger",
            confirmButtonText: "Delete",
            closeOnConfirm: false
        }, function (status) {
            if (status) {
                url = "DeleteChurchWorkerOrdination";
                ApplicationService.DeleteData(url, dataid, data).success(function (data) {
                    if (data == "DSUS") {
                        swal("Deleted!", "Details deleted successfully", "success");
                    }
                    else {
                        swal("failed", "Unable to delete this details", "error");
                    }
                    BindGrid();
                });
            }
        });
    }

}]);
